package idv.loveloser.dao;

import java.util.List;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A data access object (DAO) providing persistence and search support for
 * MdlWorkshop entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see idv.loveloser.dao.MdlWorkshop
 * @author MyEclipse Persistence Tools
 */

public class MdlWorkshopDAO extends BaseHibernateDAO {
	private static final Logger log = LoggerFactory
			.getLogger(MdlWorkshopDAO.class);
	// property constants
	public static final String COURSE = "course";
	public static final String NAME = "name";
	public static final String INTRO = "intro";
	public static final String INTROFORMAT = "introformat";
	public static final String INSTRUCTAUTHORS = "instructauthors";
	public static final String INSTRUCTAUTHORSFORMAT = "instructauthorsformat";
	public static final String INSTRUCTREVIEWERS = "instructreviewers";
	public static final String INSTRUCTREVIEWERSFORMAT = "instructreviewersformat";
	public static final String TIMEMODIFIED = "timemodified";
	public static final String PHASE = "phase";
	public static final String USEEXAMPLES = "useexamples";
	public static final String USEPEERASSESSMENT = "usepeerassessment";
	public static final String USESELFASSESSMENT = "useselfassessment";
	public static final String GRADE = "grade";
	public static final String GRADINGGRADE = "gradinggrade";
	public static final String STRATEGY = "strategy";
	public static final String EVALUATION = "evaluation";
	public static final String GRADEDECIMALS = "gradedecimals";
	public static final String NATTACHMENTS = "nattachments";
	public static final String LATESUBMISSIONS = "latesubmissions";
	public static final String MAXBYTES = "maxbytes";
	public static final String EXAMPLESMODE = "examplesmode";
	public static final String SUBMISSIONSTART = "submissionstart";
	public static final String SUBMISSIONEND = "submissionend";
	public static final String ASSESSMENTSTART = "assessmentstart";
	public static final String ASSESSMENTEND = "assessmentend";

	public void save(MdlWorkshop transientInstance) {
		log.debug("saving MdlWorkshop instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(MdlWorkshop persistentInstance) {
		log.debug("deleting MdlWorkshop instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public MdlWorkshop findById(java.lang.Long id) {
		log.debug("getting MdlWorkshop instance with id: " + id);
		try {
			MdlWorkshop instance = (MdlWorkshop) getSession().get(
					"idv.loveloser.dao.MdlWorkshop", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(MdlWorkshop instance) {
		log.debug("finding MdlWorkshop instance by example");
		try {
			List results = getSession()
					.createCriteria("idv.loveloser.dao.MdlWorkshop")
					.add(Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding MdlWorkshop instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from MdlWorkshop as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByCourse(Object course) {
		return findByProperty(COURSE, course);
	}

	public List findByName(Object name) {
		return findByProperty(NAME, name);
	}

	public List findByIntro(Object intro) {
		return findByProperty(INTRO, intro);
	}

	public List findByIntroformat(Object introformat) {
		return findByProperty(INTROFORMAT, introformat);
	}

	public List findByInstructauthors(Object instructauthors) {
		return findByProperty(INSTRUCTAUTHORS, instructauthors);
	}

	public List findByInstructauthorsformat(Object instructauthorsformat) {
		return findByProperty(INSTRUCTAUTHORSFORMAT, instructauthorsformat);
	}

	public List findByInstructreviewers(Object instructreviewers) {
		return findByProperty(INSTRUCTREVIEWERS, instructreviewers);
	}

	public List findByInstructreviewersformat(Object instructreviewersformat) {
		return findByProperty(INSTRUCTREVIEWERSFORMAT, instructreviewersformat);
	}

	public List findByTimemodified(Object timemodified) {
		return findByProperty(TIMEMODIFIED, timemodified);
	}

	public List findByPhase(Object phase) {
		return findByProperty(PHASE, phase);
	}

	public List findByUseexamples(Object useexamples) {
		return findByProperty(USEEXAMPLES, useexamples);
	}

	public List findByUsepeerassessment(Object usepeerassessment) {
		return findByProperty(USEPEERASSESSMENT, usepeerassessment);
	}

	public List findByUseselfassessment(Object useselfassessment) {
		return findByProperty(USESELFASSESSMENT, useselfassessment);
	}

	public List findByGrade(Object grade) {
		return findByProperty(GRADE, grade);
	}

	public List findByGradinggrade(Object gradinggrade) {
		return findByProperty(GRADINGGRADE, gradinggrade);
	}

	public List findByStrategy(Object strategy) {
		return findByProperty(STRATEGY, strategy);
	}

	public List findByEvaluation(Object evaluation) {
		return findByProperty(EVALUATION, evaluation);
	}

	public List findByGradedecimals(Object gradedecimals) {
		return findByProperty(GRADEDECIMALS, gradedecimals);
	}

	public List findByNattachments(Object nattachments) {
		return findByProperty(NATTACHMENTS, nattachments);
	}

	public List findByLatesubmissions(Object latesubmissions) {
		return findByProperty(LATESUBMISSIONS, latesubmissions);
	}

	public List findByMaxbytes(Object maxbytes) {
		return findByProperty(MAXBYTES, maxbytes);
	}

	public List findByExamplesmode(Object examplesmode) {
		return findByProperty(EXAMPLESMODE, examplesmode);
	}

	public List findBySubmissionstart(Object submissionstart) {
		return findByProperty(SUBMISSIONSTART, submissionstart);
	}

	public List findBySubmissionend(Object submissionend) {
		return findByProperty(SUBMISSIONEND, submissionend);
	}

	public List findByAssessmentstart(Object assessmentstart) {
		return findByProperty(ASSESSMENTSTART, assessmentstart);
	}

	public List findByAssessmentend(Object assessmentend) {
		return findByProperty(ASSESSMENTEND, assessmentend);
	}

	public List findAll() {
		log.debug("finding all MdlWorkshop instances");
		try {
			String queryString = "from MdlWorkshop";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public MdlWorkshop merge(MdlWorkshop detachedInstance) {
		log.debug("merging MdlWorkshop instance");
		try {
			MdlWorkshop result = (MdlWorkshop) getSession().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(MdlWorkshop instance) {
		log.debug("attaching dirty MdlWorkshop instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(MdlWorkshop instance) {
		log.debug("attaching clean MdlWorkshop instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}